package com.hixtrip.sample.app.service;

import com.hixtrip.sample.app.api.PayResultService;
import com.hixtrip.sample.client.constant.PayStatus;
import com.hixtrip.sample.client.order.dto.CommandPayDTO;
import com.hixtrip.sample.client.sample.vo.PayCallbackVO;
import com.hixtrip.sample.domain.order.OrderDomainService;
import com.hixtrip.sample.domain.pay.PayDomainService;
import com.hixtrip.sample.domain.pay.model.CommandPay;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 支付失败
 */
@Service(PayResultService.BEAN_NAME_PREFIX + PayStatus.PAY_FAIL_STATUS)
public class PayResultFailService implements PayResultService {

    @Autowired
    private OrderDomainService orderDomainService;

    @Autowired
    private PayDomainService payDomainService;

    /**
     * 支付失败处理
     */
    @Override
    public PayCallbackVO dealPayResult(CommandPayDTO commandPayDTO) {

        CommandPay commandPay = new CommandPay();
        BeanUtils.copyProperties(commandPayDTO, commandPay);

        // TODO
        orderDomainService.orderPayFail(commandPay);

        // 记录支付结果
        payDomainService.payRecord(commandPay);
        return null;
    }
}
